$(function () {
    addSomething();
});

function addSomething() {
    let xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4 && xhr.status === 200) {
            let s=xhr.responseText;
            let t = eval("(" + s + ")");
            let len=t.list.length;
            for(let i=0;i<len;i++){
                let name=t.list[i].name;
                let session=t.list[i].session;
                let number=t.list[i].number;
                let reason=t.list[i].message;
                let time=t.list[i].time;
                let id=t.list[i].id;
                let isAdmitted=t.list[i].isAdmitted;

                if(isAdmitted===1){
                    $("#row").append("<ul class=\"blog-meta\" style=\"text-align: center\">\n" +
                        "                <li style=\"font-size: xx-large;color: black\"><i class=\"fa fa-user\" style=\"color: #1A8BE8\"></i>"+name+"</li>\n" +
                        "            </ul>\n" +
                        "            <ul style=\"color: black;size: auto\">\n" +
                        "                    <li class=\"blogs\">\n" +
                        "                        <p class=\"secondTitle\">\n" +
                        "                            <span style=\"font-weight: bold\">原因：</span>\n" +
                        "                            <span>"+reason+"</span>\n" +
                        "                        </p>\n" +
                        "                        <span style=\"font-weight: bold\">刷题数：</span>"+number+" &nbsp&nbsp&nbsp&nbsp\n" +
                        "                        <span style=\"font-weight: bold\">年级：</span>"+session+"级&nbsp&nbsp&nbsp&nbsp\n" +
                        "                        <i class=\"fa fa-clock-o\" aria-hidden=\"true\" style=\"color: #1A8BE8\"></i>"+time+"\n" +
                        "                        <a href=\"javascript:void(0);\" onclick=\"operateColl("+id+","+isAdmitted+");\">\n" +
                        "                            <span id=\""+id+"\" style=\"cursor: pointer\">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<i style=\"color: indianred\" class=\"fa fa-heart\" aria-hidden=\"true\"></i></span>\n" +
                        "                        </a>\n" +
                        "                    </li><br/>\n" +
                        "            </ul>");
                }else if (isAdmitted === -1) {
                    $("#row").append("<ul class=\"blog-meta\" style=\"text-align: center\">\n" +
                        "                <li style=\"font-size: xx-large;color: black\"><i class=\"fa fa-user\" style=\"color: #1A8BE8\"></i>"+name+"</li>\n" +
                        "            </ul>\n" +
                        "            <ul style=\"color: black;size: auto\">\n" +
                        "                    <li class=\"blogs\">\n" +
                        "                        <p class=\"secondTitle\">\n" +
                        "                            <span style=\"font-weight: bold\">原因：</span>\n" +
                        "                            <span>"+reason+"</span>\n" +
                        "                        </p>\n" +
                        "                        <span style=\"font-weight: bold\">刷题数：</span>"+number+" &nbsp&nbsp&nbsp&nbsp\n" +
                        "                        <span style=\"font-weight: bold\">年级：</span>"+session+"级&nbsp&nbsp&nbsp&nbsp\n" +
                        "                        <i class=\"fa fa-clock-o\" aria-hidden=\"true\" style=\"color: #1A8BE8\"></i>"+time+"\n" +
                        "                        <span id=\""+id+"\"><a href=\"javascript:void(0);\" onclick=\"operateColl("+id+","+isAdmitted+");\">\n" +
                        "                            <span style=\"cursor: pointer\">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<i style=\"color: #8c8c8c\" class=\"fa fa-heart-o\" aria-hidden=\"true\"></i></span>\n" +
                        "                        </a></span>\n" +
                        "                    </li><br/>\n" +
                        "            </ul>");
                }


            }
        }
    };
    xhr.open("GET","./join_msg");
    xhr.send();

}

function operateColl(id,isAdmitted) {
    let xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4 && xhr.status === 200) {
            if(isAdmitted===-1){
                $("#"+id).html("<a href=\"javascript:void(0);\" onclick=\"operateColl("+id+","+-isAdmitted+");\">\n" +
                    "                            <span style=\"cursor: pointer\">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<i style=\"color: indianred\" class=\"fa fa-heart\" aria-hidden=\"true\"></i></span>\n" +
                    "                        </a>");
            }else {
                $("#"+id).html("<a href=\"javascript:void(0);\" onclick=\"operateColl("+id+","+-isAdmitted+");\">\n" +
                    "                            <span style=\"cursor: pointer\">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<i style=\"color: #8c8c8c\" class=\"fa fa-heart-o\" aria-hidden=\"true\"></i></span>\n" +
                    "                        </a>");
            }
        }
    };
    xhr.open("GET", "./join_msg?operateId=" + id);
    xhr.send();
}